/**
 * 
 */
package de.cbf.cam.dsa.model;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import de.cbf.cam.dsa.model.entities.OneNPC;

/**
 * @author Nebelritter
 *
 */
public class Model {

	private static Model instance= new Model();
	
	/**
	 * @uml.property  name="possibleCharacters"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="de.cbf.cam.dsa.model.entities.OneNPC"
	 */
	private List<OneNPC> possibleCharacters = new ArrayList<OneNPC>();
	/**
	 * @uml.property  name="groupCharacters"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="de.cbf.cam.dsa.model.entities.OneNPC"
	 */
	private List<OneNPC> groupCharacters 	= new ArrayList<OneNPC>();
	/**
	 * @uml.property  name="selectedCharacter"
	 * @uml.associationEnd  
	 */
	private OneNPC selectedCharacter = null;
	
	public static Model getInstance() {
		return instance;
	}
	
	public Model(){		
		
	}
	
	public List<OneNPC> getPossibleCharacters() {
		return possibleCharacters;
	}

	public boolean addPossibleCharacter(OneNPC character){
		//check for character with same name and return false in case
		return possibleCharacters.add(character);
	}
	
	public void setPossibleCharacters(List<OneNPC> possibleCharacters) {
		this.possibleCharacters = possibleCharacters;
	}
	
	public List<OneNPC> getGroupCharacters() {
		return groupCharacters;
	}
	public boolean addGroupCharacter(OneNPC character){		
		return groupCharacters.add(character);
	}
	public boolean removeGroupCharacter(OneNPC character){		
		return groupCharacters.remove(character);
	}
	
	public void setGroupCharacters(List<OneNPC> possibleCharacters) {
		this.groupCharacters = possibleCharacters;
	}
	
	public void selectCharacter(OneNPC character){
		selectedCharacter = character;
		ActionEvent event = new ActionEvent(Model.this, ActionEvent.ACTION_PERFORMED, "CharacterSelected");
		for (ActionListener listener : characterSelectedListeners) {
			listener.actionPerformed(event);
		}
	}
	
	/**
	 * @return
	 * @uml.property  name="selectedCharacter"
	 */
	public OneNPC getSelectedCharacter() {
		return selectedCharacter;
	}
		
	/**
	 * @uml.property  name="characterSelectedListeners"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="java.awt.event.ActionListener"
	 */
	private List<ActionListener> characterSelectedListeners = new ArrayList<ActionListener>();
	public boolean registerCharacterSelectedListener(ActionListener listener){
		return characterSelectedListeners.add(listener);
	}
	public boolean deRegisterCharacterSelectedListener(ActionListener listener){
		return characterSelectedListeners.remove(listener);
	}

	
	
}
